home *** CD-ROM | disk | FTP | other *** search
- typedef struct resdesc
- {
- float out1, out2; /* filter state variables */
- float a1, b1, b2; /* filter coefficients */
- } resdesc;
- static void Avoid_Underflow(resdesc *o)
- {
- /* clamp state variables */
- if(o->out1>-0.0000000001f
- && o->out1<0.0000000001f)
- o->out1 = 0.0f;
- if(o->out2>-0.0000000001f
- && o->out2<0.0000000001f)
- o->out2 = 0.0f;
- }
- /* assumes coefficients are constant throughout block */
- void Resonator(resdesc *f , int n, float *out,
- int stride, float *in, int istride )
- {
- float ym;
- int j;
-
- j=0;
- for(j=0;j<n;++j)
- {
- ym = f->b1 * f->out1 + f->b2 * f->out2
- + f->a1 * in[j*istride];
- f->out2 = f->out1;
- f->out1 = ym;
- out[j*stride] = ym;
- }
- Avoid_Underflow(f);
- }
-